/*
 * Copyright 2017-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.openmessaging.storage.dledger.protocol;

public class HeartBeatResponse extends RequestOrResponse {

    /**
     * 心跳请求处理失败时,设置当前Follower的term
     */
    public HeartBeatResponse term(long term) {
        this.term = term;
        return this;
    }

    /**
     * Follower处理心跳请求异常.
     * 包含以下情况:
     * {@link DLedgerResponseCode#UNKNOWN_MEMBER}
     * {@link DLedgerResponseCode#UNEXPECTED_MEMBER}
     * {@link DLedgerResponseCode#EXPIRED_TERM}
     * {@link DLedgerResponseCode#INCONSISTENT_LEADER}
     * {@link DLedgerResponseCode#TERM_NOT_READY}
     */
    public HeartBeatResponse code(int code) {
        this.code = code;
        return this;
    }

    /**
     * Follower处理心跳成功
     *
     * Follower返回心跳请求处理成功的条件:
     * Leader给Follower发送心跳请求 {@link DLedgerRequestCode#HEART_BEAT},
     * Follower收到心跳请求之后,进行判断:
     * 如果term和leaderId都相同,则Follower会返回成功.
     */
    public static HeartBeatResponse success(){
        return new HeartBeatResponse();
    }
}
